// ignore_for_file: must_be_immutable

import 'package:flutter/material.dart';

class AppTabbar extends StatefulWidget {
  Function(int idx) ontap;
  AppTabbar({Key? key, required this.ontap}) : super(key: key);

  @override
  _AppTabbarState createState() => _AppTabbarState();
}

class _AppTabbarState extends State<AppTabbar> {
  int idx = 0;

  List<Map<String, dynamic>> items = [
    {
      "icon": Icons.home,
      "idx": 0,
    },
    {
      "icon": Icons.search,
      "idx": 1,
    },
    {
      "icon": Icons.person,
      "idx": 2,
    },
  ];

  @override
  void initState() {
    super.initState();
  }

  tapHandle(item) {
    idx = item["idx"];
    setState(() {});
    widget.ontap(idx);
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> icons = [];
    for (var item in items) {
      var icon = Expanded(
        child: Container(
          padding: const EdgeInsets.only(bottom: 10),
          color: idx == item["idx"] ? Colors.black : Colors.white,
          child: InkWell(
            onTap: () {
              tapHandle(item);
            },
            child: Icon(
              item["icon"],
              size: 22,
              color: idx != item["idx"] ? Colors.black : Colors.white,
            ),
          ),
        ),
      );
      icons.add(icon);
    }

    return Material(
      child: Container(
        height: 44,
        color: Colors.white,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: icons,
        ),
      ),
    );
  }
}
